package xy.web.util;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

public class Util {
	public static String getRomdomStr(){
		return "t"+new Date().getTime();
	}

	public static String getUrlRoot(HttpServletRequest req){
		String url=req.getRequestURL().toString();	
		String uri = req.getRequestURI();
		String root = req.getContextPath();
		
		String head = "";
		int pos = 0;
		if(uri.equals("/")){
			pos = url.indexOf(uri,url.indexOf("//")+2);
		}else{
			pos = url.indexOf(uri);
		}
		head = url.substring(0,pos);
		
		if(!head.endsWith("/")){
			head += "/";
		}
		if(!root.equals("")){
			if(root.startsWith("/")){
				root = root.substring(1);
			}
			head += root;
		}
		if(head.endsWith("/")){
			head = head.substring(0, head.length()-1);
		}
		return head;
	}


}
